--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_wriggle_nightbug = General:new(extension, "hy_wriggle_nightbug", "chi_k", 3, 3, General.Female)

    local bug_parasitism = fk.CreateSkill {
        name = "bug_parasitism",
    }
    bug_parasitism:addEffect(fk.GameStart, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(bug_parasitism.name)
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local cards = room:getCardsFromPileByRule("slash", 2, "drawPile")
            if #cards > 0 then
                room:obtainCard(player, cards, false, fk.ReasonPrey, player, bug_parasitism.name, "@@bug_parasitism")
            end
        end,
    })
    bug_parasitism:addEffect(fk.AfterCardsMove, {
        is_delay_effect = true,
        can_trigger = function(self, event, target, player, data)
            local cards = {}
            for _, move in ipairs(data) do
                if move.toArea == Card.DiscardPile then
                    for _, info in ipairs(move.moveInfo) do
                        if Fk:getCardById(info.cardId):getMark("@@bug_parasitism") ~= 0 then
                            table.insertIfNeed(cards, info.cardId)
                        end
                    end
                end
            end
            if #cards > 0 then
                event:setCostData(self, cards)
                return player:hasSkill(bug_parasitism.name)
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            room:obtainCard(player, event:getCostData(self), true, fk.ReasonPrey, player, bug_parasitism.name, "bug_parasitism_prohibit-round")
        end,
    })
    bug_parasitism:addEffect("targetmod", {
        bypass_distances = function(self, player, skill, card, to)
            if player:hasSkill(bug_parasitism.name) and card:getMark("@@bug_parasitism") ~= 0 then
                return true
            end
        end,
        bypass_times = function(self, player, skill, scope, card, to)
            if player:hasSkill(bug_parasitism.name) and card:getMark("@@bug_parasitism") ~= 0 then
                return true
            end
        end
    })
    bug_parasitism:addEffect("prohibit", {
        prohibit_use = function(self, player, card)
            if player:hasSkill(bug_parasitism.name) and card:getMark("bug_parasitism_prohibit-round") ~= 0 then
                return true
            end
        end
    })

    local worm_damage = fk.CreateSkill {
        name = "worm_damage",
    }
    worm_damage:addEffect(fk.AfterCardsMove, {
        can_trigger = function(self, event, target, player, data)
            local targets = {}
            for _, move in ipairs(data) do
                if move.toArea == Card.PlayerHand and move.to ~= player then
                    for _, info in ipairs(move.moveInfo) do
                        if Fk:getCardById(info.cardId):getMark("@@bug_parasitism") ~= 0 then
                            table.insertIfNeed(targets, move.to)
                        end
                    end
                end
            end
            if #targets > 0 then
                event:setCostData(self, targets)
                return player:hasSkill(bug_parasitism.name)
            end
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local targets = event:getCostData(self)
            room:sortByAction(targets)
            local choice1 = "worm_damage_choice1::" .. player.id
            local choice2 = "worm_damage_choice2::" .. player.id
            for _, t in ipairs(targets) do
                local result = room:askToChoice(t, {
                    skill_name = worm_damage.name,
                    prompt = "worm_damage_prompt",
                    choices = { choice1, choice2 }
                })
                if result == choice1 then
                    room:drawCards(player, 2, worm_damage.name)
                elseif result == choice2 then
                    room:addPlayerMark(t, "@worm_damage", 1)
                end
            end
        end
    })
    worm_damage:addEffect(fk.DamageInflicted, {
        is_delay_effect = true,
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(worm_damage.name) and data.from and data.from == player and data.to:getMark("@worm_damage") > 0
        end,
        on_use = function(self, event, target, player, data)
            data:changeDamage(data.to:getMark("@worm_damage"))
            player.room:setPlayerMark(data.to, "@worm_damage", 0)
        end
    })
    worm_damage:addEffect(fk.Damage, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(worm_damage.name) and data.from and data.from == player and data.to ~= player and data.card and data.card:getMark("@@bug_parasitism") ~= 0
        end,
        on_cost = function(self, event, target, player, data)
            return player.room:askToSkillInvoke(player, {
                skill_name = worm_damage.name,
                prompt = "worm_damage_prompt2::" .. data.to.id .. ":" .. data.card:toLogString()
            })
        end,
        on_use = function(self, event, target, player, data)
            player.room:obtainCard(data.to, data.card, true, fk.ReasonPrey, player, worm_damage.name)
        end
    })

    local catch_fire = fk.CreateSkill {
        name = "catch_fire",
    }
    catch_fire:addEffect(fk.Damaged, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(catch_fire.name) and data.to == player and data.damageType == fk.FireDamage
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local selections = {}
            for _, id in ipairs(player:getCardIds("h")) do
                if Fk:getCardById(id):getMark("@@bug_parasitism") ~= 0 then
                    table.insertIfNeed(selections, id)
                end
            end
            local pattern = "invalid"
            if #selections > 0 then
                pattern = ".|.|.|.|.|.|" .. table.concat(selections, ",")
            end
            local cards = room:askToCards(player, {
                skill_name = catch_fire.name,
                prompt = "catch_fire_prompt",
                min_num = 1,
                max_num = 1,
                pattern = pattern,
            })
            if #cards == 1 then
                room:moveCards({
                    ids = cards,
                    from = player,
                    toArea = Card.DrawPile,
                    skillName = catch_fire.name,
                    proposer = player,
                    moveReason = fk.ReasonPut,
                    moveVisible = false
                })
            else
                room:loseHp(player, 1, catch_fire.name)
            end
        end
    })

    extension:loadSkillSkels { bug_parasitism, worm_damage, catch_fire }
    hy_wriggle_nightbug:addSkills { "bug_parasitism", "worm_damage", "catch_fire" }

    Fk:loadTranslationTable {
        ["hy_wriggle_nightbug"] = "莉格露",
        ["#hy_wriggle_nightbug"] = "烬作尘烟",
        ["illustrator:hy_wriggle_nightbug"] = "六夜",
        ["designer:hy_wriggle_nightbug"] = "黑曜人形",
        ["cv:hy_wriggle_nightbug"] = "",

        ["bug_parasitism"] = "虫寄",
        [":bug_parasitism"] = "游戏开始时，从牌堆中随机获得两张【杀】并令之获得“虫”标记。“虫”进入弃牌堆后，你获得之且本轮无法再使用之。你使用“虫”无距离次数限制。",
        ["@@bug_parasitism"] = "虫",

        ["worm_damage"] = "侵蛀",
        [":worm_damage"] = "其他角色获得“虫”后须选择一项：1.令你摸两张牌；2.下次受到你造成的伤害+1。你使用“虫”对其他角色造成伤害后，可以令其获得之。",
        ["worm_damage_prompt"] = "侵蛀：你须选择一项",
        ["worm_damage_choice1"] = "令%dest摸两张牌",
        ["worm_damage_choice2"] = "下次受到%dest造成的伤害+1",
        ["@worm_damage"] = "侵蛀",
        ["worm_damage_prompt2"] = "侵蛀：你可以令%dest获得%arg",

        ["catch_fire"] = "引蝶",
        [":catch_fire"] = "在你受到火焰伤害后，你须选择一项：1.将一张“虫”置于牌堆顶；2.失去1点体力。",
        ["catch_fire_prompt"] = "引蝶：你须将一张“虫”置于牌堆顶，否则失去1点体力",
    }
end
